<style>
.part,.help-block{display:none;}
</style>
<div class="col-lg-12">
    <section class="panel">
        <header class="panel-heading">
            快递信息(Express information)
        </header>
        <div class="panel-body">
            <div class="position-center">
                <form action="/index/goods/goods_deal_add"role="form" method="post" id="i_form"> 
                <div class="form-group">
                    <label for="exampleInputPassword1">快递单(Express No.)<span style="color:red;"><b>*必填</b></span></label>
                    <input type="hidden" name="id" value="{$data['id']}">
                    <input name="order_No" type="text" value="{$data['order_No']}" class="form-control" id="exampleInputPassword1"><p class="help-block"></p>
                </div>
                <div class="form-group">
                    <label for="exampleInputPassword1">收件类型(Express Type)</label>
                        <select class="form-control m-bot15" name="e_type">
  
                            <option value="1" {if condition="$data['e_type'] eq 1"}selected{/if}>LBC</option>
                            <option value="2" {if condition="$data['e_type'] eq 2"}selected{/if}>AP CARGO</option>
                        </select>  
                </div>
                <div class="form-group">
                    <label for="exampleInputPassword1">快递内容(Express Detail)<span style="color:red;"><b>*必填</b></span></label>
                    <textarea name="content" class="form-control"  id="exampleInputPassword1" >{$data['content']}</textarea>
                </div>
                <div class="form-group">
                    <label for="exampleInputPassword1">收件门店(Branch)</label>
                        <select class="form-control m-bot15" name="branch">
                             {volist name="cate_list" id="data1"}
                            <option value="{$data1.id}" {if condition="$data1['id'] eq $data[branch]"}selected{/if}>{$data1.name}</option>
                            {/volist}
                        </select>  
                </div>
                <div class="form-group part">
                    <label for="exampleInputPassword1">收件部门(Part)</label>
                        <select class="form-control m-bot15" name="part">
                             {volist name="cate_list1" id="data2"}
                            <option value="{$data2.id}" {if condition="$data2['id'] eq $data[branch]"}selected{/if}>{$data2.name}</option>
                            {/volist}
                            
                        </select>  
                </div>                                 
               {if condition="$data['id'] and $data['from_branch'] neq $_SESSION['admin_id']"}
                <div class="form-group">
                    <input type="checkbox" id="status2" name="status" value="1"  {if condition="$data['status'] eq 1"}checked{/if}>
                    <label for="status2">已收到(received)</label>
                </div> 
                {/if}
                {if condition="$data['id']"}
                {if condition="$data['status'] eq 0 and ($data['from_branch'] eq $_SESSION['admin_id'] or ($data['branch'] eq 1 and $data['part'] eq $_SESSION['admin_id']))"}
                <button type="button" class="btn btn-info add_order" >Submit</button>
                {/if}
                {else:}
                <button type="button" class="btn btn-info add_order" >Submit</button>
                {/if}
            </form>
            </div>

        </div>
    </section>

</div>
<script type="text/javascript">
$(function(){
    var flag=2;
    $("select[name='branch']").change(function(){
        if('1'==$(this).val()){
            $(".part").show();
        }else{
            $(".part").hide();
        }
    })
    gs();
    $(".add_order").click(function(){
        if($("input[name='order_No']").val()==''||$("input[name='order_No']").val()=='undefined'||isNaN($("input[name='order_No']").val())){
            $("input[name='order_No']").parent().addClass('has-error')
            return;
        }


        if($("textarea[name='content']").val()==''||$("input[name='content']").val()=='undefined'){
            $("input[name='content']").parent().addClass('has-error')
            return;
        } 
        if(flag==2)
        $("#i_form").submit();      
    })
    $("input[name='order_No']").change(function(){
        if($(this).val()==''||$(this).val()=='undefined'){
            $("input[name='order_No']").parent().addClass('has-error')
            return;
        }else if($("input[name='order_No']").parent().hasClass("has-error")){
            $("input[name='order_No']").parent().removeClass('has-error')
        } 
        var url='/index/goods/order_no_check/ono/'+$(this).val()+'/oid/{$data.id}'
        $.post(url, { name: 1},function(data){
            if(data.status=='0'){
                flag=2;
                $(".help-block").hide()
            }else{
                $(".help-block").html('<span style="color:red;">Express No. already exists</span>').show()
                flag=1
            }
        },'json');          
    })
    $("textarea[name='content']").change(function(){
        if($(this).val()==''||$(this).val()=='undefined'){
            $("textarea[name='content']").parent().addClass('has-error')
            flat=1
            return;
        }else if($("textarea[name='content']").parent().hasClass("has-error")){
            $("textarea[name='content']").parent().removeClass('has-error')
            flag=2;
        }       
    })    
})
function gs(){
    if('1'==$("select[name='branch']").val()){
        $(".part").show();
    }else{
        $(".part").hide();
    }    
}
</script>